package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.BVehicleClassService;
import cn.huiyunche.base.service.mappers.BVehicleClassMapper;
import cn.huiyunche.base.service.mappers.ext.BVehicleClassExtMapper;
import cn.huiyunche.base.service.model.BVehicleClass;
import cn.huiyunche.base.service.model.BVehicleClassExample;
import cn.huiyunche.base.service.vo.BVehicleClassVo;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BVehicleClassServiceImpl implements BVehicleClassService {

    private static final Logger LOGGER = LoggerFactory.getLogger(BVehicleClassServiceImpl.class);

    @Autowired
    private BVehicleClassExtMapper bVehicleClassExtMapper;

    @Autowired
    private BVehicleClassMapper bVehicleClassMapper;

    @Override
    public List<BVehicleClassVo> getList() {
        BVehicleClassExample example = new BVehicleClassExample();
        example.setOrderByClause(" sort ASC");
        return bVehicleClassExtMapper.selectList(example);
    }

    @Override
    public List<BVehicleClass> getLists(List<String> classes) {
        LOGGER.info("getLists params : {}", classes.size());
        BVehicleClassExample example = new BVehicleClassExample();
        example.setOrderByClause(" sort ASC");
        if (CollectionUtils.isNotEmpty(classes)) {
            example.createCriteria().andVehicleClassIn(classes);
        }
        return bVehicleClassMapper.selectByExample(example);
    }

    @Override
    public BVehicleClass getByVehicleClass(String vehicleClass) {
        LOGGER.info("getByVehicleClass param : {}", vehicleClass);
        if (StringUtils.isBlank(vehicleClass)) {
            LOGGER.error("getByVehicleClass vehicleClass must not be blank");
            throw new IllegalArgumentException("车型类别不能为空");
        }

        BVehicleClassExample example = new BVehicleClassExample();
        example.createCriteria().andVehicleClassEqualTo(vehicleClass);
        List<BVehicleClass> list = bVehicleClassMapper.selectByExample(example);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0);
        }
        return null;
    }

}
